package lanqiao14;
// OK
import java.util.Arrays;
import java.util.Scanner;

public class G {
	private static int N;
	private static int[] relaArr;
	private static int[] arr;
	private static int sum = 0;
	private static boolean[] arr1;
	
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		N = scan.nextInt();
		relaArr = new int[N];
		arr = new int[N + 1];
		arr1 = new boolean[N + 1];
		Arrays.fill(arr1, true);
		for (int i = 1; i < relaArr.length; i++) {
			relaArr[i] = scan.nextInt();
		}
		scan.close();
		sorts(1);
		System.out.println(sum);
	}
	
	// 找到所有满足条件的排列的可能
	private static void sorts(int index) {
		if (index == N + 1) {
			sum++;
			return;
		}
		for (int i = 1; i <= N; i++) {
			if (arr1[i] &&  judge(i - arr[index - 1], index)) {
				arr1[i] = false;
				arr[index] = i;
				sorts(index + 1);
				arr1[i] = true;
			}
		}
	}
	
	// 判断该数位是否满足条件
	private static boolean judge(int n, int index) {
		if (index == 1) {
			return true;
		}
		if (relaArr[index - 1] == 0 && n != 1 && index != 1) {
			return true;
		}
		if (relaArr[index - 1] == 1 && n == 1) {
			return true;
		}
		return false;
	}
}
